package swordoffer.offer03;

/*
    面试题3：数组中重复的数字，第二种解法：原地置换。
 */
public class Solution2 {
    public int findRepeatNumber(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            while (nums[i] != i){
                if (nums[nums[i]] == nums[i]){
                    return nums[i];
                }
                int temp = nums[i];
                nums[i] = nums[temp];
                nums[temp] = temp;
            }

        }
        return -1;
    }

    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] nums = {2,3,1,0,2,5,3};
        int repeatNumber = solution2.findRepeatNumber(nums);
        System.out.println(repeatNumber);
    }
}
